package com.tencent.qf.common.gateway.qwRobot;

import com.alibaba.fastjson.JSON;
import com.tencent.qf.common.gateway.qwRobot.vo.QwRobotDataVo;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: p_haojiawu@tencent.com
 * @date: 2023-06-06 18:21
 **/

@Component
public class QwRobotUtil {

    public String createPostData(String chatid,String msgtype, String contentValue) {
        QwRobotDataVo wcd = new QwRobotDataVo();
        wcd.setChatid(chatid);
        wcd.setMsgtype(msgtype);
        Map<Object, Object> content = new HashMap<>();
        content.put("content", contentValue);
        if ("markdown".equals(msgtype)) {
            wcd.setMarkdown(content);
        } else {
            wcd.setText(content);
        }
        return JSON.toJSONString(wcd).replace("\\\\", "\\");
    }

    public String parseTemplate(HashMap<String, String> params,String template) {
        for (String key : params.keySet()) {
            template = template.replace("{" + key + "}", params.get(key));
        }
        return template;
    }
}
